package com.service.impl;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.MailUserMapper;
import com.entity.MailUser;
import com.service.UserService;
import com.utils.MailUtils;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private MailUserMapper mailUserMapper;

	@Override
	public void insert(MailUser entity) {
	
		mailUserMapper.insert(entity);
		//发送激活邮件
		try {
			MailUtils.sendMail(entity.getEmail(), entity.getCode());
		} catch (AddressException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void update(String CODE) {
		mailUserMapper.updateByCode(CODE, 1);
	}

}
